import { NetDispatcher } from "../../../mvc/core/NetDispatcher";
import { ServerCommand } from "../../mvc/ServerCommand";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { Cache } from "../../cache/Cache";
import { PetDrugItemInfo } from "../avatar/PetDrugItemInfo";
import { SDrugBagInfo } from "../../../../Message/Game/SDrugBagInfo";
import { EDrug } from "../../../../Message/Public/EDrug";
import { PetDrugBagItem } from "../avatar/PetDrugBagItem";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { DataEvent } from "../../events/DataEvent";
type int = number;
//class PetDrugBagSprite
    
    export  class PetDrugBagSprite /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            NetDispatcher.addCmdListener(ServerCommand.PetDrugBagInfoUpdate, this.onPetDrugBagInfoUpdateHandler);
            Dispatcher.addEventListener(EventName.PetUseDrugBagSuccess, this.onPetUseDrugBagSuccessHandler);
            Cache.instance.timeCdCache.petLifeCD.addCompleteFunction(this.cdComplete);
            this.useHandCursor = true;
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onClickHandler);
            return;
        }

        public get petDrugItemInfo(): PetDrugItemInfo
        {
            return this._petDrugItemInfo;
        }

        public set petDrugItemInfo(arg1: PetDrugItemInfo)
        {
            this._petDrugItemInfo = arg1;
            this._lifeDrugBagItem.petDrugItemInfo = arg1;
            return;
        }

        /* internal  */init(): void
        {
            var loc1=new SDrugBagInfo();
            loc1.type = EDrug._EDrugLifePetBag;
            this._lifeDrugBagItem = new PetDrugBagItem();
            this._lifeDrugBagItem.drugBagData = loc1;
            this._lifeDrugBagItem.useHandCursor = true;
            this.addChild(this._lifeDrugBagItem);
            return;
        }

        /* internal  */onPetDrugBagInfoUpdateHandler(arg1: SDrugBagInfo): void
        {
            if (arg1) 
            {
                if (arg1.type == EDrug._EDrugLifePetBag) 
                {
                    if (arg1.remain == 0) 
                    {
                        this._lifeDrugBagItem.filters = [FilterConst.colorFilter];
                        Cache.instance.autoResumeSet.isPetUsingLifeDrugBag = false;
                    }
                    else 
                    {
                        this._lifeDrugBagItem.filters = [];
                        Cache.instance.autoResumeSet.isPetUsingLifeDrugBag = true;
                    }
                    this._lifeDrugBagItem.drugBagData = arg1;
                }
            }
            return;
        }

        /* internal  */onPetUseDrugBagSuccessHandler(arg1: DataEvent): void
        {
            var loc2=null;
            var loc1=arg1.data as int;
            if (loc1 == EDrug._EDrugLifePetBag) 
            {
                loc2 = Cache.instance.timeCdCache.petLifeCD;
                loc2.startCoolDown();
                Dispatcher.dispatchEvent(new DataEvent(EventName.ItemUse, loc2));
            }
            return;
        }

        /* internal  */cdComplete(): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetAutoResume));
            return;
        }

        /* internal  */onClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.DrugBagWindowOpen, 2));
            return;
        }

        /* internal */ /* var */_lifeDrugBagItem: PetDrugBagItem;

        /* internal */ /* var */_petDrugItemInfo: PetDrugItemInfo;
    }
